package com.ellricky.excute_president.ui.activity.school

import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.ScreenUtil
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.http.callback.ECallback
import com.ellricky.baselib.adapter.GridItemDecoration
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.excute_president.*
import kotlinx.android.synthetic.main.pd_activity_work_log.*

class WorkLogActivity : BaseToolBarActivity<Void, BasePresenter<Void>>() {

    private lateinit var adapter: WorkLogAdapter
    private var dataSource: List<WorkLogListEntity> = listOf()

    override fun getContentLayout() = R.layout.pd_activity_work_log

    override fun initUIView() {
        super.initUIView()
        mTvTitle.setText(R.string.pd_work_log)


        val glm = object : GridLayoutManager(this, 2) {
            override fun canScrollVertically(): Boolean {
                return false
            }
        }

        rv.layoutManager = glm
        rv.addItemDecoration(
                GridItemDecoration(ScreenUtil.dpUnit(this, 0f).toInt()
                        , ScreenUtil.dpUnit(this, 0f).toInt(), android.R.color.transparent)
        )
        rv.isNestedScrollingEnabled = false

        adapter = WorkLogAdapter()
        rv.adapter = adapter

        ivArrow.setOnClickListener(this)

        loadData()

    }


    private fun loadData() {
        val url = EAppUtil.getApiHost() + API_WORK_LOG
        val paramMap = hashMapOf<String, Any>()
        HttpUtils.getInstance().post(url, paramMap, object : ECallback<WorkLogEntity>(this) {
            override fun onSuccess(data: WorkLogEntity?, msg: String?) {

                data?.let {
                    tvAreaName.text = it.areanName
                    tvTotal.text = it.totalPrice
                    dataSource = listOf(
                            WorkLogListEntity("消课率", it.classNum, ""),
                            WorkLogListEntity("报名率", it.vipStudentNum, ""),
                            WorkLogListEntity("续费率", it.priceNum, ""),
                            WorkLogListEntity("体验成功率", it.classSucNum, ""),
                            WorkLogListEntity("转介绍人数", it.stuNum, "人"),
                            WorkLogListEntity("自然进店人数", it.inSchoolNum, "人"))

                    adapter.refresh(dataSource)

                }


            }
        })
    }


    override fun onClickView(v: View?) {
        super.onClickView(v)
        when (v) {
            ivArrow -> EAppUtil.jumpPageWithNoParam(this, TotalIncomeActivity::class.java)
        }
    }
}
